<?php 
include "../../config/ini.php";
include INCLUDES."head.php";
?>
<link rel="stylesheet" href="<?=SITE?>files/css/plugins/fullcalendar.css" type="text/css" media="screen"/>
<script type="text/javascript" src="<?=SITE?>files/js/fullcalendar.js"></script>
<script type="text/javascript" src="<?=SITE?>files/js/gcal.js"></script>
<script type='text/javascript'>
function resizeContent(){
	var contentSize = $("#content").width();
	var bodyWidth = $("body").width();
	var bodyHeight = $(window).height();
	
	if(contentSize < 1000){
		$("#content").width(1000);		
	}else if(bodyWidth >= 1000){
		$("#content").width("100%");
	}
	
	$('#calendar').fullCalendar('option', 'height', bodyHeight - 112);
}

$(document).ready(function() {
	$('#calendar').fullCalendar({
		viewDisplay: function(view){
			loadCalendar();
		},
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek,agendaDay'
		},
		eventClick: function(event) {
			if(event.idSprint > 0){
				var html = '<div class="event_description"><h1>'+event.title+' ('+event.meetingType+')</h1>';
								html +=	'<b>Dia: </b>'+event.dateEvent+'<br>';
								html +=	'<b>Hora Inicial: </b>'+event.hourInit+'<br>';
								html +=	'<b>Hora Final: </b>'+event.hourEnd+'<br>';
								html +=	'<b>Criado por: </b>'+event.nameCriator+'<br>';
								html +=	'<b>Descrição:</b><br>'+event.description;
								html +=	'</div>';

				$(this).qtip({
					content: html,
					position: {
						corner: {
							tooltip: "bottomLeft",
							target: "topLeft"
						},
						adjust: { screen: true }
					},
					show: {
						when: true,
						ready: true
					},
					hide: { 
						fixed: true, 
						delay: 1000 
					}, 
					style: {
						border: {
							width: 3,
							radius: 5
						},
						width: { 
							min: 150,
							max: 400
						},
						padding: 8, 
						textAlign: 'left',
						tip: true,
						background: '#FFFFFF'
					}
				});
			}else{
				window.open(event.url, 'gcalevent', 'width=700,height=600');
			}
			return false;
		},
		events:'<?=$_SESSION["PROJECT"]->urlCalendarGoogle?>'
	});

	resizeContent();
});

$(window).resize(function() {
	resizeContent();
});


function loadCalendar(){
	$.ajax({
		url: SITE+"app/Views/V_Meeting.php?f=getMeetingsCalendar",
		async: false,
		success: function(data){
			var obj = JSON.decode(data);
			
			if(obj[0]){
				$('#calendar').fullCalendar('removeEvents');
				$('#calendar').fullCalendar('addEventSource',obj[1]);
			}else{
				
			}
		}
	});
}
</script>
</head>
<body>
<div class="box_modal" id="overlay"></div>

<?include INCLUDES."header.php";?>
<div id="wrapper">
	<div id="content">
		<div class="spacer">
			<div id="box_content"><div id="calendar"></div></div>
		</div>
	</div>
</div>
</body>
</html>
